package com.scsj.supermarket.adapter;

import android.util.Log;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.scsj.supermarket.R;
import com.scsj.supermarket.bean.QueryShopInTradeBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 首页以及很多地方用到的fragment中的商品列表adapter
 */

public class QueryShopInTradeAdapter extends BaseQuickAdapter<QueryShopInTradeBean.DataBean.ListBean, BaseViewHolder> {
    //用来存放商圈下所有店铺的集合
    List<QueryShopInTradeBean.DataBean.ListBean> shopInTrades = new ArrayList<>();
    public QueryShopInTradeAdapter(List data) {
        super(R.layout.item_goods_list_base_layout1, data);
        this.shopInTrades= data;
    }

    @Override
    protected void convert(BaseViewHolder helper, QueryShopInTradeBean.DataBean.ListBean item) {
        for (int i = 0; i < shopInTrades.size(); i++) {
            //店铺名字
            String shopName = shopInTrades.get(i).getName();
            //店铺id
            String shopId = shopInTrades.get(i).getId();
            //店铺logo
            String shopLogo = shopInTrades.get(i).getUrl();
            Log.e("店铺Logo::",shopLogo+"999");
            //星级评价
            double starNum = shopInTrades.get(i).getColligateScores();
            //距离
            String disTance= String.valueOf(shopInTrades.get(i).getDistance());
            //起送费
            String qiSongFei= String.valueOf(shopInTrades.get(i).getOriginPrice());
            //配送费
            String deliveryFei= String.valueOf(shopInTrades.get(i).getMinDeliveryFee());
            //销量
           // double saleNum= (double) shopInTrades.get(i).getGrossSales();

            //给店铺控件设置值
            TextView shopNameTv= helper.getView(R.id.index_name_tv);
            shopNameTv.setText(shopName);
            ImageView shopLogoIv= helper.getView(R.id.index_icon_iv);

            Glide.with(mContext).
                    load(shopLogo).
                    diskCacheStrategy(DiskCacheStrategy.RESULT).
                    thumbnail(0.5f).
                    placeholder(R.drawable.ic_launcher_background).
                    priority(Priority.LOW).
                    error(R.drawable.ic_launcher_background).
                    fallback(R.drawable.ic_launcher_background).
                    into(shopLogoIv);
            RatingBar ratingBar= helper.getView(R.id.index_comm_rb);
            ratingBar.setNumStars((int) starNum);
            TextView disTanceTv= helper.getView(R.id.index_content_tv);
            disTanceTv.setText(qiSongFei+"元起送,距离："+disTance+",基础运费"+deliveryFei+"元");
            TextView saleNumTv= helper.getView(R.id.index_num_tv);
           // saleNumTv.setText("月销"+saleNum+"单");

        }
    }
}
